package com.book.service.impl;

import com.book.dao.UserMapper;
import com.book.entity.User;
import com.book.service.UserService;
import com.book.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.http.HttpSession;

/*
 **@Author:youpeng
 **Created on 2022/4/24
 */
public class UserServiceImpl implements UserService {
    @Override
    public boolean auth(String username, String password, HttpSession session) {
        try(SqlSession sqlSession= MybatisUtil.getSession()){
            UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
            User user = userMapper.selectUser(username, password);
            if(user==null) return false;
            session.setAttribute("user",user);
            return true;
        }
    }

    @Override
    public int addUser(String username, String nickname, String password) {
        try(SqlSession sqlSession= MybatisUtil.getSession()){
            UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
            return userMapper.addUser(username, nickname, password);
        }
    }
}
